import { defineStore } from "pinia";
import {reqBannerList, reqComprehensiveList, reqCourseList, reqRecommendList} from "../api/home";
import moment from 'moment'

export default defineStore('home',{
    state:() =>{
        return{
            swiperImgList:[],
            recommendList:[],
            comprehensiveList:[],
            hotExerciseList:[],
            newRuiList:[],
            newsList:[],

            courseList:[]
        }
    },

    actions:{
        // 获取轮播图列表
        async getBannerData(){
            try{
                const re = await reqBannerList()
                this.swiperImgList = re.data.data.content.map((item:any) => item.appAdvertiseUrl)
                console.log(re,111)
            } catch (e){
                return Promise.reject(e)
            }
        },
        // 获取推荐视频列表
        async getRecommendData(pageSize:any, pageNum:any){
            try{
                const re = await reqRecommendList(pageSize, pageNum)
                this.recommendList = re.data.data.content
                console.log(re,222)
            }catch (e){
                return Promise.reject(e)
            }
        },

        // 作品
        // 综合榜
        async getComprehensiveList(pageSize:any, pageNum:any){
            try{
                const re = await reqComprehensiveList(pageSize, pageNum)
                this.comprehensiveList = re.data.data.content
                console.log(re,333)
            }catch (e){
                return Promise.reject(e)
            }
        },

        // 教程
        // 综合榜
        async getCourseData(pageSize:any, pageNum:any){
            try{
                const re = await reqCourseList(pageSize, pageNum)
                this.courseList = re.data.data.content
                console.log(re,"aaa")
            }catch (e){
                return Promise.reject(e)
            }
        },


    }
})
